//
//  musicTableViewController.m
//  B项目
//
//  Created by lanou on 16/8/9.
//  Copyright © 2016年 Work. All rights reserved.
//

#import "musicTableViewController.h"
#import "musicTableViewCell.h"
#import "detailMusicTableViewController.h"
#import "PrefixHeader.pch"
@interface musicTableViewController ()
@property(nonatomic,strong)NSArray *array;
@property(nonatomic,strong)UILabel *titleLable;
@property(nonatomic,strong)UIImageView *imgVBack;
@property(nonatomic,strong)UIImageView *imgLine;
@property(nonatomic,strong)NSArray *urlArray;

@end

@implementation musicTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"音乐";
    UIBarButtonItem *leftBT = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back.png"] style:(UIBarButtonItemStylePlain) target:self action:@selector(leftAction)];
    self.navigationItem.leftBarButtonItem = leftBT;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];

    //模糊视图
    UIImage *backImg = [UIImage imageNamed:@"11471923,2560,1600.jpg"];
    UIImageView *imgV = [[UIImageView alloc]initWithImage:backImg];
    self.tableView.backgroundView = imgV;

    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:(UIBlurEffectStyleLight)];
    UIVisualEffectView *effectivew = [[UIVisualEffectView alloc]initWithEffect:blur];
    effectivew.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    [imgV addSubview:effectivew];

    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"musicTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];
    self.array = @[@[@"华语男歌手", @"华语女歌手", @"华语乐队组合"],@[@"欧美男歌手", @"欧美女歌手", @"欧美乐队组合"], @[@"韩语男歌手", @"韩语女歌手", @"韩语乐队组合"], @[@"日语男歌手", @"日语女歌手", @"日语乐队组合"], @[@"其它歌手"]];
    
    self.urlArray = @[@[@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=6&sex=1&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=6&sex=2&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=6&sex=3&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore"], @[@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=3&sex=1&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=3&sex=1&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=3&sex=3&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore"], @[@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=7&sex=1&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=7&sex=2&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=7&sex=3&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore"], @[@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=60&sex=1&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=60&sex=2&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore", @"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=60&sex=3&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore"], @[@"http://tingapi.ting.baidu.com/v1/restserver/ting?method=baidu.ting.artist.getList&format=json&order=1&limit=50&offset=0&area=5&sex=4&abc=%E7%83%AD%E9%97%A8&from=ios&version=5.2.5&from=ios&channel=appstore"]];



}



- (void)leftAction
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

#pragma mark - Table view data source

//section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

//row
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.array[section] count];
}

//row 高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

//cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    musicTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.titleLable.text = self.array[indexPath.section][indexPath.row];

    return cell;
}


//section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSArray *array = @[@"华语乐坛",@"欧美流行",@"韩语乐坛",@"日语乐坛",@"其他"];
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 0, kScreenWidth -20, 46)];
    view1.backgroundColor = [UIColor whiteColor];
    UILabel *titleLable = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, kScreenWidth -100, 30)];
    titleLable.textColor = [UIColor cyanColor];

    UIView *viewLine = [[UIView alloc]initWithFrame:CGRectMake(10, 45, view1.ownWidth, 2)];
    viewLine.backgroundColor = [UIColor whiteColor];
    [view1 addSubview:titleLable];
    [view1 addSubview:viewLine];
    if (section == 0) {
        titleLable.text = array[0];
    }else if (section == 1){
        titleLable.text = array[1];
    }else if (section == 2) {
        titleLable.text = array[2];
    }else if (section == 3){
        titleLable.text = array[3];
    }else{
        titleLable.text = array[4];
    }

    view1.backgroundColor = [UIColor clearColor];

    return view1;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 46;
}


//点击进入详情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    detailMusicTableViewController *detailMusicVC = [[detailMusicTableViewController alloc]init];
    detailMusicVC.listUrl = self.urlArray[indexPath.section][indexPath.row];
    [self.navigationController pushViewController:detailMusicVC animated:YES];
    
}





/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
